from itertools import permutations

def has_property(num):
    divisor = [1, 2, 3,  5, 7, 11, 13, 17]
    for i in xrange(1, 8):
        value = num[i] * 100 + num[i+1] * 10 + num[i+2]
        if value % divisor[i] != 0:
            return False
    return True

total = 0
for num in permutations(range(0, 10), 10):
    if has_property(num):
        total += int(''.join(map(str, num)))
print total
